package com.hollysys.hollimsa.biz.istio.enhanceservice.service.impl;

import com.hollysys.hollimsa.biz.istio.enhanceservice.dao.EnhanceServiceDao;
import com.hollysys.hollimsa.biz.istio.enhanceservice.domain.EnhanceServiceDictDTO;
import com.hollysys.hollimsa.biz.istio.enhanceservice.service.EnhanceServiceService;
import com.hollysys.hollimsa.common.filter.tenantinfo.TenantInfoContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wangyuxi
 * @date 2020/11/08
 **/
@Component
public class EnhanceServiceServiceImpl implements EnhanceServiceService {

    @Autowired
    private EnhanceServiceDao enhanceServiceDao;


    /**
     * 获取当前命名空间的全部服务
     * @return 服务下拉
     */
    @Override
    public List<EnhanceServiceDictDTO> getAllKubernetesServices() {
        final String namespace = TenantInfoContext.getTenantNS();
        return enhanceServiceDao.getAllKubernetesServices(namespace).stream().map(svc -> EnhanceServiceDictDTO.builder().label(svc.getMetadata().getName()).value(svc.getMetadata().getName()).build()).collect(Collectors.toList());
    }
}
